package util

import (
	"encoding/hex"
	"github.com/satori/go.uuid"
)

func NewUUID() string {
	return uuid.NewV1().String()
}

func NewNameUUID(name string) string {
	id := uuid.NewV1()
	return uuid.NewV3(id, name).String()
}

func NewNameUUIDByte(name string) []byte {
	id := uuid.NewV1()
	return uuid.NewV3(id, name).Bytes()
}

func UUIDtoString(u []byte) string {
	buf := make([]byte, 36)

	hex.Encode(buf[0:8], u[0:4])
	buf[8] = '-'
	hex.Encode(buf[9:13], u[4:6])
	buf[13] = '-'
	hex.Encode(buf[14:18], u[6:8])
	buf[18] = '-'
	hex.Encode(buf[19:23], u[8:10])
	buf[23] = '-'
	hex.Encode(buf[24:], u[10:])

	return string(buf)
}
